package com.offer;

import com.bean.TreeNode;

/**
 * @Author: huangzhigao
 * @Date: 2023/3/4 17:37
 */
public class offer26 {
    public boolean isSubStructure(TreeNode A, TreeNode B) {
        if (A == null || B == null) {
            return false;
        }
        return isContain(A, B) || isSubStructure(A.left, B) || isSubStructure(B.right, B);
    }


    public boolean isContain(TreeNode A, TreeNode B) {
        if (B == null) {
            return true;
        }
        if (A == null || A.val != B.val) {
            return false;
        }

        return isContain(A.left,B.left) && isContain(A.right,B.right);
    }
}
